home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 August: Tool Chest / Dev.CD Aug 00 TC Disk 1.toast / pc / sample code / graphics 2d / drawline / drawline.c next >
Encoding:
C/C++ Source or Header  |  2000-06-23  |  2.5 KB  |  128 lines

  1. /*
  2.     File:        DrawLine.c
  3.  
  4.     Contains:    This application shows how to use the QuickDraw     
  5.                 pattern mode 'srcCopy' to invert the intersection    
  6.                 of the two green lines.    
  7.  
  8.     Written by: Greg Henderson    
  9.  
  10.     Copyright:    Copyright © 1995-1999 by Apple Computer, Inc., All Rights Reserved.
  11.  
  12.                 You may incorporate this Apple sample source code into your program(s) without
  13.                 restriction. This Apple sample source code has been provided "AS IS" and the
  14.                 responsibility for its operation is yours. You are not permitted to redistribute
  15.                 this Apple sample source code as "Apple sample source code" after having made
  16.                 changes. If you're going to re-distribute the source, we require that you make
  17.                 it clear in the source that the code was descended from Apple sample source
  18.                 code, but that you've made changes.
  19.  
  20.     Change History (most recent first):
  21.                 7/9/1999    Karl Groethe    Updated for Metrowerks Codewarror Pro 2.1
  22.                 
  23.  
  24. */
  25. #include <Controls.h>
  26. #include <Quickdraw.h>
  27. #include <Fonts.h>
  28. #include <Windows.h>
  29. #include <Menus.h>
  30. #include <TextEdit.h>
  31. #include <Dialogs.h>
  32. #include <Sound.h>
  33.  
  34. #define KBaseResID            128
  35. #define kMoveToFront        (WindowPtr)-1L
  36.  
  37.  
  38. /*********************/
  39. /*    Functions         */
  40. /*********************/
  41.  
  42. void    ToolBoxInit( void );
  43. void    WindowInit( void );
  44. void    DrawLine( void );
  45.  
  46.  
  47. /*************** main ***************/
  48.  
  49. void    main( void )
  50.  
  51. {
  52.     ToolBoxInit();
  53.     WindowInit();
  54.     DrawLine();
  55.     
  56.     while ( !Button() );
  57.     
  58. }
  59.  
  60. /*************** ToolBoxInit ***************/
  61.  
  62. void    ToolBoxInit( void )
  63.  
  64. {
  65.     InitGraf(&qd.thePort);          /* init Quickdraw and global variables        */
  66.     InitFonts();
  67.     InitWindows();
  68.     InitMenus();
  69.     TEInit();
  70.     InitDialogs( nil );
  71.     InitCursor();
  72.     
  73. }
  74.  
  75. /*************** WindowInit ***************/
  76.  
  77. void    WindowInit( void )
  78.  
  79. {
  80.     WindowPtr    window;
  81.  
  82.     window = GetNewCWindow( KBaseResID, nil, kMoveToFront );
  83.     
  84.     if ( window == nil )
  85.     {
  86.         SysBeep ( 10 );    /* Couldn't load the WIND resource! */
  87.         ExitToShell();
  88.     }
  89.     
  90.     ShowWindow( window );
  91.     SetPort( window );
  92. }
  93.  
  94. /*************** Draw two Lines ***************/
  95.  
  96. void    DrawLine( )
  97. {
  98.     Rect        pictureRect;
  99.     WindowPtr    window;    
  100.     
  101.     window    =    FrontWindow();
  102.     pictureRect = window->portRect;
  103.     
  104.     PenNormal() ;
  105.     PenSize(5,5);
  106.  
  107.     ForeColor( blackColor );
  108.         PenMode(srcCopy);
  109.          MoveTo(  50, 47 );
  110.         LineTo( 300,231 );
  111.         
  112.          PenMode(srcXor);
  113.         MoveTo( 400, 47 );
  114.         LineTo( 200,231 ); 
  115.     
  116.     
  117.        ForeColor( greenColor );
  118.         PenMode(addMax);
  119.          MoveTo( 50, 47 );
  120.         LineTo(300,231);
  121.         
  122.         PenMode(addMax);
  123.         MoveTo( 400, 47 );
  124.         LineTo( 200,231 ); 
  125.     
  126. }
  127.  
  128.